package jiejie.jianzhioffer;

public class offer22 {
    public static void main(String[] args) {

    }
    /**
     * 倒数第K个节点
     * @param head
     * @param k
     * @return
     */
    public static ListNode getKthFromEnd(ListNode head, int k) {
        if(head==null)
            return null;
        ListNode fast=head;
        ListNode slow=head;
        for(int i=0; i<k; i++)
            fast=fast.next;
        while(fast!=null){
            fast=fast.next;
            slow=slow.next;
        }
        return slow;
    }
}